﻿#define _CRT_SECURE_NO_WARNINGS 1
#include"SeqList.h"
//顺序表就是数组，但是在数组的基础上，它还要求数组是从头1开始连续存储的，不能跳过间断

void TestSeqList1()
{
	SL s1;
	SeqListInit(&s1);

	int a = 0;
	cout << "输入你要输入数据的个数" << endl;
	cin >> a;
	//尾插入数据
	for (int i = 0; i < a; i++)
	{
		//尾插
		SeqListPushBack(&s1, i);
	}
	
	//打印数据
	cout << "尾插入数据后打印结果为：";
	SeqListPrint(&s1);

	//尾删除数据
	SeqListPopBack(&s1);
	cout << "尾删除一个数据后打印结果为：";
	SeqListPrint(&s1);

	//头插入3个数据
	SeqListPushFront(&s1, 10);
	SeqListPushFront(&s1, 20);
	SeqListPushFront(&s1, 30);

	//打印数据
	cout << "头插入3个数据后打印结果为：";
	SeqListPrint(&s1);

	//头删除2个数据
	SeqListPopFront(&s1);
	SeqListPopFront(&s1);

	//打印数据
	cout << "头删除2个数据后打印结果为：";
	SeqListPrint(&s1);


	//查找数据并返回下标
	cout << "请输入你想要查找的数字";
	SlDateType findnum = 0;
	cin >> findnum;
	SlDateType ret=SeqListFind(&s1, findnum);
	if (ret == -1)
	{
		cout << endl << "找不到这个数字!!!";
	}
	else
	{
		cout << endl << "找到了其下标为:" << ret;
	}

	//在指定位置插入数据
	cout << endl << "请在指定下标输入你想要输入的数据";
	int pos = 0;
	SlDateType x = 0;
	cout << endl << "请输入你先要输入数据的下标" << endl;
	cin >> pos;
	cout << "请输入你想输入的数据" << endl;
	cin >> x;
	SeqListInsert(&s1, pos, x);
	cout << "输入数据后的顺序表为:";
	SeqListPrint(&s1);

	//在指定的pos下标删除数据
	cout << "请输入你想要删除数据位置的下标" << endl;
	cin >> pos;
	SeqListErase(&s1, pos);
	cout << "删除指定位置数据后的顺序表为:";
	SeqListPrint(&s1);

	SeqListDestory(&s1);
}

//写一个类似通讯录的菜单
void menu()
{
	cout << "************************" << endl;
	cout << "请选择你的操作:>" << endl;
	cout << "0,退出程序" << endl;
	cout << "1,头插入数据			2,头删除数据" << endl;
	cout << "3,尾插入数据			4,尾删除数据" << endl;
	cout << "5,指定下标位置插入数据		6,指定下标删除数据" << endl;
	cout << "7,查找指定下标位置是否有数据	8,打印顺序表" << endl;
	cout << "************************" << endl;
}


int main()
{
	//TestSeqList1();
	SL s1;		
	SlDateType x = 0;
	SlDateType ret = 0;
	int pos = 0;
	SeqListInit(&s1);
	int input = 0;
	
	do
	{
		menu();
		cout << "请选择:" << endl;
		cin >> input;
		switch (input)
		{
		case 0:
			SeqListDestory(&s1);
			break;
		case 1:
			cout << "请输入你想要插入的数据" << endl;
			cin >> x;
			SeqListPushFront(&s1,x);
			cout << "插入成功!" << endl;
			break;
		case 2:
			SeqListPopFront(&s1);
			cout << "删除成功!" << endl;
			break;
		case 3:
			cout << "请输入你想要插入的数据" << endl;
			cin >> x;
			SeqListPushBack(&s1, x);
			cout << "插入成功!" << endl;
			break;
		case 4:
			SeqListPopBack(&s1);
			cout << "删除成功!" << endl;
			break;
		case 5:
			cout << "请输入你想要插入数据的下标位置" << endl;
			cin >> pos;
			cout << "请输入你想要输入数据" << endl;
			cin >> x;
			SeqListInsert(&s1, pos, x);
			cout << "插入成功!" << endl;
			break;
		case 6:
			cout << "请输入你想要删除数据的下标位置" << endl;
			cin >> pos;
			SeqListErase(&s1, pos);
			cout << "删除成功!" << endl;
			break;
		case 7:
			cout << "请输入你想要查找的数据" << endl;
			cin >> x;
			ret = SeqListFind(&s1, x);
			if (ret == -1)
			{
				cout << "找不到这个数据" << endl;
			}
			else
			{
				cout << "找到了，这个数据的下标为:" << ret << endl;
			}
			break;
		case 8:
			SeqListPrint(&s1);
			break;
		default:
			cout << "选择错误。请重新选择!" << endl;
			break;
		}

	} while (input);

	return 0;
} 